import 'package:dk_flutter_base/dk_core.dart';
import 'package:dk_flutter_base/dk_ui.dart';
import 'package:dk_flutter_module_sale/common/config/page_base_common.dart';
import 'package:dk_flutter_module_sale/common/user_track/user_track.dart';
import 'package:dk_flutter_module_sale/config/route/common_widget_route.dart';
import 'package:dk_flutter_module_sale/sale/api/sale_in_api.dart';
import 'package:dk_flutter_module_sale/sale/sale_in/following_record/bean/following_detail_bean.dart';
import 'package:dk_flutter_module_sale/sale/sale_in/following_record/widget/only_text_widget.dart';
import 'package:dk_flutter_module_sale/sale/sale_in/following_record/widget/record_input_widget.dart';

@ARoute(url: CommonWidgetRoute.COMMON_FOLLOWING_RECORD_DETAIL)
class PageFollowingRecordDetail extends CommonPageWithTrack {
  final BoostRouteOption option;
  PageFollowingRecordDetail(this.option) : super();

  @override
  void trackStatistics() {
    UserTrack.trackViewScreen("收房-房源跟进记录-详情", null);
  }

  @override
  void onInitState(CommonPageBloc pageBloc, {Map<String, Bloc> extraBlocMap}) {
    Map<String, dynamic> param = Map<String, dynamic>();
    param["dataId"] = this.option.params["dataId"];
    pageBloc.pageHttpGet(
        path: SaleInApi.followRecordDetailUrl,
        queryMap: param,
        widgetBuilderByData: (dynamic data) {
          //DataListBean
          List<RecordDetailBean> list = (data as List != null)
              ? (data as List).map((item) {
                  RecordDetailBean bean = RecordDetailBean.fromJson(item);
                  return bean;
                }).toList()
              : null;
          return FollowingRecordDetailWidget(pageBloc, list);
        });
  }
}

class FollowingRecordDetailWidget extends StatefulWidget {
  final CommonPageBloc pageBloc;
  final List<RecordDetailBean> list;
  FollowingRecordDetailWidget(this.pageBloc, this.list);
  @override
  FollowingRecordDetailState createState() {
    return FollowingRecordDetailState(this.pageBloc);
  }
}

class FollowingRecordDetailState extends State<FollowingRecordDetailWidget>
    with SingleTickerProviderStateMixin {
  CommonPageBloc pageBloc;
  FollowingRecordDetailState(this.pageBloc);
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: DkAppBar(DKAppBarParams.withBackNoMenu(pageBloc.context,
          titleContent: "跟进记录详情")),
      backgroundColor: Colors.white,
      body: SafeArea(
        bottom: true,
        child: Container(
          color: Colors.white,
          child: ListView.builder(
            itemBuilder: (BuildContext context, int index) {
              RecordDetailBean recordDetailBean = this.widget.list[index];
              return recordDetailBean.showType ==
                      AnswerContentShowType.AnswerContentShowTypeOnlyText
                  ? OnlyTextWidget(detailBean: recordDetailBean,)
                  : RecordInputWidget(detailBean: recordDetailBean,);
            },
            itemCount: this.widget.list.length,
          ),
        ),
      ),
    );
  }

  @override
  void dispose() {
    super.dispose();
  }
}
